package com.example.tms.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import com.example.tms.config.MDCCleanupFilter;

@EnableAspectJAutoProxy
@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LogInterceptor())
                .addPathPatterns("/employees/**");
    }

    @Bean
    public FilterRegistrationBean<MDCCleanupFilter> mdcCleanupFilter() {
        FilterRegistrationBean<MDCCleanupFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new MDCCleanupFilter());
        registrationBean.setOrder(Integer.MAX_VALUE); // 设置为最后执行
        return registrationBean;
    }
}
